package com.itany.cms.interceptor;

import com.itany.cms.entity.User;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
public class CheckLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User) request.getSession().getAttribute("user");
        if (user == null){
            request.setAttribute("loginMsg","用户尚未登录，请先登录");
            request.getRequestDispatcher("/showLogin").forward(request,response);
            return false;
        }
        return true;
    }
}
